package MapReduce.mapJoin;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;


import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class mapJoinMain {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException, URISyntaxException {
        // 1 获取Job
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        // 2 获取jar包路径
        job.setJarByClass(mapJoinMain.class);

        // 3 关联Mapper和Reducer
        job.setMapperClass(mapJoinMapper.class);
//        job.setReducerClass(reduceJoinReducer.class);

        // 4 设置map输出的K V类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(NullWritable.class);

        // 5 设置最终的输出K V类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(NullWritable.class);

        // 此处不需要reduce阶段因为数据已经在map阶段处理完成
        job.setNumReduceTasks(0);

        // 加载缓存数据
        job.addCacheFile(new URI("file:///D:/中国科学院大学硕士/学习类文件夹/BigDataDev/Input/tablecache/pd.txt"));

        // 6 设置输入输出路径
        FileInputFormat.addInputPath(job, new Path("D:\\中国科学院大学硕士\\学习类文件夹\\BigDataDev\\Input\\inputtable2"));
        FileOutputFormat.setOutputPath(job, new Path("D:\\中国科学院大学硕士\\学习类文件夹\\BigDataDev\\Output\\output4"));

        // 7 提交Job
        boolean waitForCompletion = job.waitForCompletion(true);
        System.exit(waitForCompletion ? 0 : 1);
    }
}
